#include <map>
#include <iostream>
#include <string>

using namespace std;

int main() {
	map<string, int> words;
	while (true)
	{
		string input_str;
		cin >> input_str;
		if (input_str == "QUIT") {
			break;
		}
		map<string, int>::iterator iter = words.find(input_str);
		if (iter == words.end()) {
			words.insert(make_pair(input_str, 1));
			cout << 0 << endl;
		}
		else {
			cout << iter->second << endl;
			iter->second++;
		}
	}
}